CC	= ${ENV_CPP}

CFLAGS = -c -g -W \
-O3 \
-Wall \
-Werror \
-Wshadow \
-Wno-long-long \
-Wpointer-arith \
-D_REENTRANT \
-D_POSIX_PTHREAD_SEMANTICS \
-D_USE_FAST_MACRO

###########################################################
#Check system:
#       Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
SYSLIB = -lpthread -lz -ldl
CHECKSYSRES = @echo "Unknow system type!";exit 1
OSNAME = $(shell uname -sm)
UNIXNAME = $(OSNAME)
RPATH =

ifeq ($(CC),)
        CC = g++
endif

ifeq ($(findstring clang++, $(CC)), clang++)
	CFLAGS += -Wno-invalid-source-encoding -Wno-invalid-offsetof
endif

#Find system type.
ifneq ($(SYSPATH),)
	CHECKSYSRES = @echo "System is $(shell uname -sm)"
endif
###########################################################
SRC =
CFLAGS += -I. -I../libhttp
LDFLAGS = -L../libhttp -lhttp -Wl,-rpath,../libhttp $(EXTLIBS) $(SYSLIB)

COMPILE = $(CC) $(CFLAGS)
LINK = $(CC) $(OBJ) $(LDFLAGS)

###########################################################
OBJ_PATH = .

#Project's objs
SRC += $(wildcard *.cpp)
OBJ  = $(patsubst %.cpp, $(OBJ_PATH)/%.o, $(notdir $(SRC)))

$(OBJ_PATH)/%.o: %.cpp
	$(COMPILE) $< -o $@

.PHONY = all clean
all: RM $(OBJ)
	$(LINK) -o $(PROG)
	$(shell cp ../libhttp/libhttp.so .)
	@echo ""
	@echo "All ok! Output:$(PROG)"
	@echo ""
rebuild rb: clean all
RM:
	rm -f $(PROG)
clean cl:
	rm -f $(PROG)
	rm -f $(OBJ)
	rm -f libhttp.so

rebuild rb: clean all
###########################################################
